<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>userList</title>
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}"></link>
    <script type="text/javascript" th:src="@{/js/My97DatePicker/WdatePicker.js}"></script>
    <script type="text/javascript" src="/js/My97DatePicker/lang/zh-cn.js"></script>
    <script type="text/javascript" th:src="@{/js/jquery/jquery-1.10.2.min.js}"></script>
</head>
<body class="container">
<br/>
<h1>账单列表</h1>
<br/><br/>

<div class="with:80%">
    <form class="form-inline" id="qf" method="post">
        <div class="form-group">
            <label for="typeId" class="control-label">类型</label>
            <select name="typeId" id="typeId" class="form-control">
                <option value="">全部</option>
                <option th:each="t : ${types}" th:value="${t.id}" th:text="${t.name}"
                        th:selected="(${bill.typeId} == ${t.id})"></option>
            </select>
        </div>

        <input type="hidden" name="pageNum" id="pageNum" th:value="${pageInfo.pageNum }" />
        <input type="hidden" name="pageSize" id="pageSize" th:value="${pageInfo.pageSize }" />
        <div class="form-group">
            <label for="date1" class="control-label">开始时间</label>
            <input type="text" class="form-control" name="startTime" id="startTime" placeholder="开始时间"
                   th:value="*{bill.startTime} ? *{#dates.format(bill.startTime, 'yyyy-MM-dd')}"
                   onclick="WdatePicker()"/>
        </div>
        <div class="form-group">
            <label for="date2" class="control-label">结束时间</label>
            <input type="text" class="form-control" name="endTime" id="endTime" placeholder="结束时间"
                   th:value="*{bill.endTime} ? *{#dates.format(bill.endTime, 'yyyy-MM-dd')}" onclick="WdatePicker()"/>
        </div>
        <div class="form-group">
            <input type="submit" value="查询" class="btn btn-info"/>
            &nbsp; &nbsp;
            <input type="reset" value="重置" class="btn btn-info"/>
            &nbsp; &nbsp;
            <a href="/bill/toAdd" class="btn btn-info">添加</a>
        </div>
    </form>
</div>
<br/>


<div class="with:80%">
    <table class="table table-striped table-bordered">
        <thead>
        <tr>
            <th>序号</th>
            <th>标题</th>
            <th>时间</th>
            <th>金额</th>
            <th>类别</th>
            <th>说明</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="b , index : ${pageInfo.list}">
            <th th:text="${b.id}">#</th>
            <th th:text="${b.title}">标题</th>
            <th th:text="${b.time} ? ${#dates.format(b.time,'yyyy-MM-dd hh:mm:ss')}">时间</th>
            <th th:text="${b.price}">金额</th>
            <th th:text="${b.type.name}">类别</th>
            <th th:text="${b.explains}">说明</th>
            <th>
                <a th:href="|toUpdate/${b.id}|">修改</a>
                <a th:href="|delete/${b.id}|">删除</a>
            </th>
        </tr>
        </tbody>
    </table>
</div>
<ul class="pagination">
    <li>
        <button class="btn btn-default" id="first">第一页</button>
    </li>
    <li>
        <button class="btn btn-default" id="prev">上一页</button>
    </li>
    <li th:each="p : ${pageInfo.navigatepageNums}">
        <button class="btn btn-default" name="pn" th:text="${p}" th:disabled="(${p} == ${pageInfo.pageNum})"></button>
    </li>
    <li>
        <button class="btn btn-default" id="next">下一页</button>
    </li>
    <li>
        <button class="btn btn-default" id="last">最后页</button>
    </li>
</ul>
</body>
<script>
    $(function () {
        var pageNum = [[${pageInfo.pageNum}]]; //当前页
        var pageCount = [[${pageInfo.pages}]];//最后页
        var hasNextPage = [[${pageInfo.hasNextPage}]];//还有下一页
        var hasPreviousPage = [[${pageInfo.hasPreviousPage}]];//还有上一页
        $("#next").click(function(){
            $("#pageNum").val(pageNum + 1);
            $("#qf").submit();
        });
        $("#prev").click(function(){
            $("#pageNum").val(pageNum - 1);
            $("#qf").submit();
        });
        $("#first").click(function(){
            $("#pageNum").val(1);
            $("#qf").submit();
        });
        $("#last").click(function(){
            $("#pageNum").val(pageCount);
            $("#qf").submit();
        });
        //没有上一页
        if (!hasPreviousPage) {
            $("#prev").prop("disabled", true);
            $("#first").prop("disabled", true);
        };
        //没有下一页
        if (!hasNextPage) {
            $("#next").prop("disabled", true);
            $("#last").prop("disabled", true);
        };
        $("button[name='pn']").click(function(){
            $("#pageNum").val($(this).html());
            $("#qf").submit();
        });
    });
</script>
</html>